home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / emacs-18.59src.lha / emacs-18.59 / lisp / sup-mouse.el < prev    next >
Encoding:
Text File  |  1992-11-21  |  6.3 KB  |  217 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                         ;;
  3. ;;    File:     sup-mouse.el                             ;;
  4. ;;    Author:   Wolfgang Rupprecht                         ;;
  5. ;;    Created:  Fri Nov 21 19:22:22 1986                     ;;
  6. ;;    Contents: supdup mouse support for lisp machines             ;;
  7. ;;                                         ;;
  8. ;;     (from code originally written by John Robinson@bbn for the bitgraph)  ;;
  9. ;;                                         ;;
  10. ;;    $Log: sup-mouse.el,v $
  11. ; Revision 1.2.1.1  1992/11/21  15:55:33  dgay
  12. ; Amiga patches
  13. ;
  14. ; Revision 1.2  1992/11/15  13:29:56  dgay
  15. ; emacs18.59
  16. ;
  17. ; Revision 1.1  1992/11/15  10:09:42  dgay
  18. ; Initial revision
  19. ;                                     ;;
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.  
  22. ;; GNU Emacs code for lambda/supdup mouse
  23. ;; Copyright (C) Free Software Foundation 1985, 1986
  24.  
  25. ;; This file is part of GNU Emacs.
  26.  
  27. ;; GNU Emacs is free software; you can redistribute it and/or modify
  28. ;; it under the terms of the GNU General Public License as published by
  29. ;; the Free Software Foundation; either version 1, or (at your option)
  30. ;; any later version.
  31.  
  32. ;; GNU Emacs is distributed in the hope that it will be useful,
  33. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35. ;; GNU General Public License for more details.
  36.  
  37. ;; You should have received a copy of the GNU General Public License
  38. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  39. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  40.  
  41. ;;;  User customization option:
  42.  
  43. (defvar sup-mouse-fast-select-window nil
  44.   "*Non-nil for mouse hits to select new window, then execute; else just select.")
  45.  
  46. (defconst mouse-left 0)
  47. (defconst mouse-center 1)
  48. (defconst mouse-right 2)
  49.  
  50. (defconst mouse-2left 4)
  51. (defconst mouse-2center 5)
  52. (defconst mouse-2right 6)
  53.  
  54. (defconst mouse-3left 8)
  55. (defconst mouse-3center 9)
  56. (defconst mouse-3right 10)
  57.  
  58. ;;;  Defuns:
  59.  
  60. (defun sup-mouse-report ()
  61.   "This function is called directly by the mouse, it parses and
  62. executes the mouse commands.
  63.  
  64.  L move point          *  |---- These apply for mouse click in a window.
  65. 2L delete word            |
  66. 3L copy word          | If sup-mouse-fast-select-window is nil,
  67.  C move point and yank *  | just selects that window.
  68. 2C yank pop          |
  69.  R set mark            *  |
  70. 2R delete region      |
  71. 3R copy region          |
  72.  
  73. on modeline            on \"scroll bar\"    in minibuffer
  74.  L scroll-up            line to top        execute-extended-command
  75.  C proportional goto-char   line to middle    mouse-help
  76.  R scroll-down            line to bottom    eval-expression"
  77.   
  78.   (interactive)
  79.   (let*
  80. ;; expect a string of <esc>:<buttons>;<x-pos>;<y-pos>c
  81.       ((buttons (sup-get-tty-num ?\;))
  82.        (x (sup-get-tty-num ?\;))
  83.        (y (sup-get-tty-num ?c))
  84.        (window (sup-pos-to-window x y))
  85.        (edges (window-edges window))
  86.        (old-window (selected-window))
  87.        (in-minibuf-p (eq y (1- (screen-height))))
  88.        (same-window-p (and (not in-minibuf-p) (eq window old-window)))
  89.        (in-modeline-p (eq y (1- (nth 3 edges))))
  90.        (in-scrollbar-p (>= x (1- (nth 2 edges)))))
  91.     (setq x (- x (nth 0 edges)))
  92.     (setq y (- y (nth 1 edges)))
  93.  
  94. ;    (error "mouse-hit %d %d %d" buttons x y) ;;;; debug
  95.  
  96.     (cond (in-modeline-p
  97.        (select-window window)
  98.        (cond ((= buttons mouse-left)
  99.           (scroll-up))
  100.          ((= buttons mouse-right)
  101.           (scroll-down))
  102.          ((= buttons mouse-center)
  103.           (goto-char (/ (* x
  104.                    (- (point-max) (point-min)))
  105.                 (1- (window-width))))
  106.           (beginning-of-line)
  107.           (what-cursor-position)))
  108.        (select-window old-window))
  109.       (in-scrollbar-p
  110.        (select-window window)
  111.        (scroll-up
  112.         (cond ((= buttons mouse-left)
  113.            y)
  114.           ((= buttons mouse-right)
  115.            (+ y (- 2 (window-height))))
  116.           ((= buttons mouse-center)
  117.            (/ (+ 2 y y (- (window-height))) 2))
  118.           (t
  119.            0)))
  120.        (select-window old-window))
  121.       (same-window-p
  122.        (cond ((= buttons mouse-left)
  123.           (sup-move-point-to-x-y x y))
  124.          ((= buttons mouse-2left)
  125.           (sup-move-point-to-x-y x y)
  126.           (kill-word 1))
  127.          ((= buttons mouse-3left)
  128.           (sup-move-point-to-x-y x y)
  129.           (save-excursion
  130.             (copy-region-as-kill
  131.              (point) (progn (forward-word 1) (point))))
  132.           (setq this-command 'yank)
  133.           )
  134.          ((= buttons mouse-right)
  135.           (push-mark)
  136.           (sup-move-point-to-x-y x y)
  137.           (exchange-point-and-mark))
  138.          ((= buttons mouse-2right)
  139.           (push-mark)
  140.           (sup-move-point-to-x-y x y)
  141.           (kill-region (mark) (point)))
  142.          ((= buttons mouse-3right)
  143.           (push-mark)
  144.           (sup-move-point-to-x-y x y)
  145.           (copy-region-as-kill (mark) (point))
  146.           (setq this-command 'yank))
  147.          ((= buttons mouse-center)
  148.           (sup-move-point-to-x-y x y)
  149.           (setq this-command 'yank)
  150.           (yank))
  151.          ((= buttons mouse-2center)
  152.           (yank-pop 1))
  153.          )
  154.        )
  155.       (in-minibuf-p
  156.        (cond ((= buttons mouse-right)
  157.           (call-interactively 'eval-expression))
  158.          ((= buttons mouse-left)
  159.           (call-interactively 'execute-extended-command))
  160.          ((= buttons mouse-center)
  161.           (describe-function 'sup-mouse-report)); silly self help 
  162.          ))
  163.       (t                ;in another window
  164.        (select-window window)
  165.        (cond ((not sup-mouse-fast-select-window))
  166.          ((= buttons mouse-left)
  167.           (sup-move-point-to-x-y x y))
  168.          ((= buttons mouse-right)
  169.           (push-mark)
  170.           (sup-move-point-to-x-y x y)
  171.           (exchange-point-and-mark))
  172.          ((= buttons mouse-center)
  173.           (sup-move-point-to-x-y x y)
  174.           (setq this-command 'yank)
  175.           (yank))
  176.          ))
  177.       )))
  178.  
  179.  
  180. (defun sup-get-tty-num (term-char)
  181.   "Read from terminal until TERM-CHAR is read, and return intervening number.
  182. Upon non-numeric not matching TERM-CHAR signal an error."
  183.   (let
  184.       ((num 0)
  185.        (char (read-char)))
  186.     (while (and (>= char ?0)
  187.         (<= char ?9))
  188.       (setq num (+ (* num 10) (- char ?0)))
  189.       (setq char (read-char)))
  190.     (or (eq term-char char)
  191.     (error "Invalid data format in mouse command"))
  192.     num))
  193.  
  194. (defun sup-move-point-to-x-y (x y)
  195.   "Position cursor in window coordinates.
  196. X and Y are 0-based character positions in the window."
  197.   (move-to-window-line y)
  198.   (move-to-column x)
  199.   )
  200.  
  201. (defun sup-pos-to-window (x y)
  202.   "Find window corresponding to screen coordinates.
  203. X and Y are 0-based character positions on the screen."
  204.   (let ((edges (window-edges))
  205.     (window nil))
  206.     (while (and (not (eq window (selected-window)))
  207.         (or (<  y (nth 1 edges))
  208.             (>= y (nth 3 edges))
  209.             (<  x (nth 0 edges))
  210.             (>= x (nth 2 edges))))
  211.       (setq window (next-window window))
  212.       (setq edges (window-edges window))
  213.       )
  214.     (or window (selected-window))
  215.     )
  216.   )
  217.